package com.sbwebsocket.core.model.contants;

import com.sbwebsocket.core.model.bo.DirectMessageBody;
import com.sbwebsocket.core.model.bo.FanoutMessageBody;
import com.sbwebsocket.core.model.bo.TopicMessageBody;
import lombok.Getter;

/**
 * 消息类型
 * @Auther: GSJ
 * @Date: 2022/2/10
 * @Description:
 * @version: 1.0
 */
@Getter
public enum WsMessageType {

    DIRECT(1, DirectMessageBody.class),
    FANOUT(10, FanoutMessageBody.class),
    //发送给特定主题用户，消息体中必须有主题相关描述类
    TOPIC(20, TopicMessageBody.class);

    int type;
    Class messageBodyClz;

    WsMessageType(int type,Class messageBodyClz){
        this.type = type;
        this.messageBodyClz = messageBodyClz;
    }
    
    public static WsMessageType valueOf(int type){
        for (WsMessageType value : WsMessageType.values()) {
            if(value.type == type) return value;
        }
        return null;
    }
}
